package com.ke.forum.forumapi.controller;


import com.ke.forum.common.common.Result;
import com.ke.forum.forumapi.service.CommentService;
import com.ke.forum.mbg.entity.Comment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 珂
 * @since 2022-05-22
 */
@RestController
@RequestMapping("/comment")
public class CommentController {

    @Autowired
    CommentService commentService;

    @PostMapping("addComment")
    public Result addComment(@RequestBody @Validated Comment comment){
        return commentService.addComment(comment);
    }

    @GetMapping("listComment")
    public Result listComment(@RequestParam(value = "articleId")Integer articleId,
                              @RequestParam(value = "current")Integer current){
        return commentService.listComment(articleId, current);
    }

    @GetMapping("listReply")
    public Result listReply(@RequestParam(value = "commentId") Integer commentId,
                            @RequestParam(value = "current") Integer current){
        return commentService.listReply(commentId,current);
    }

    @GetMapping("deleteComment")
    public Result deleteComment(@RequestParam(value = "id")Integer id){
        return commentService.deleteComment(id);
    }

}

